package com.acctrue.common.jwt.config;

import com.acctrue.common.jwt.filter.JwtFilter;
import com.acctrue.common.jwt.filter.MyFeignRequestInterceptor;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author: jsc
 * @createTime: 2023-11-22 19:02
 * @version: 1.0.0
 * @Description: 请求拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private JwtFilter jwtFilter;

    /**
     * 不需要拦截地址
     */
    public static final String[] EXCLUDE_URLS = {
            "/login/**"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtFilter).addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_URLS);
    }

    @Bean
    public RequestInterceptor requestInterceptor() {
        return new MyFeignRequestInterceptor();
    }
}
